<?php
namespace app\common\model\member;
use app\common\model\file\FileModel;
use think\Model;

class MemberIdCardModel extends Model
{
    // 表名
    protected $name = 'member_id_card';
    // 表主键
    protected $pk = 'id';

    /**
     * 关联身份证正面
     * @Author: 易军辉
     * @DateTime:2024-07-31 15:49
     * @return \think\model\relation\HasOne
     */
    public function cardFront()
    {
        return $this->hasOne(FileModel::class, 'file_id', 'card_front_id')->append(['file_url'])->where(where_disdel());
    }

    /**
     * 获取身份证正面链接
     * @Author: 易军辉
     * @DateTime:2024-07-31 15:48
     * @param $value
     * @param $data
     * @return string
     */
    public function getCardFrontUrlAttr($value, $data)
    {
        return $this['cardFront']['file_url'] ?? '';
    }

    /**
     * 关联身份证反面
     * @Author: 易军辉
     * @DateTime:2024-07-31 15:49
     * @return \think\model\relation\HasOne
     */
    public function cardOpposite()
    {
        return $this->hasOne(FileModel::class, 'file_id', 'card_opposite_id')->append(['file_url'])->where(where_disdel());
    }

    /**
     * 获取身份证反面链接
     * @Author: 易军辉
     * @DateTime:2024-07-31 15:48
     * @param $value
     * @param $data
     * @return string
     */
    public function getCardOppositeUrlAttr($value, $data)
    {
        return $this['cardOpposite']['file_url'] ?? '';
    }

    /**
     * 关联手持身份证
     * @Author: 易军辉
     * @DateTime:2024-07-31 15:49
     * @return \think\model\relation\HasOne
     */
    public function cardHand()
    {
        return $this->hasOne(FileModel::class, 'file_id', 'card_hand_id')->append(['file_url'])->where(where_disdel());
    }

    /**
     * 获取手持身份证链接
     * @Author: 易军辉
     * @DateTime:2024-07-31 15:48
     * @param $value
     * @param $data
     * @return string
     */
    public function getCardHandUrlAttr($value, $data)
    {
        return $this['cardHand']['file_url'] ?? '';
    }

    /**
     * 关联用户
     * @Author: 易军辉
     * @DateTime:2024-08-02 10:26
     * @return \think\model\relation\HasOne
     */
    public function member()
    {
        return $this->hasOne(MemberModel::class, 'member_id', 'member_id');
    }
}
